
[dbo].[temp_GetBusinessItem]
CREATE PROCEDURE [dbo].[temp_GetBusinessItem]
@tablename varchar(256),
@namespace varchar(256) = null,
@baseclass varchar(256) = 'BusinessItem' AS
BEGIN
SET NOCOUNT ON
IF @namespace IS NOT NULL
BEGIN
SELECT
'
using System;
using Asi;
using Asi.Business;
using System.Data;
using Asi.Business.Common;
namespace Asi.Business.' + @namespace + '
{
public class ' + @tablename + ' : ' + @baseclass + '
{
#region Constructors
/// <summary>
/// Initializes a new instance of <see cref="' + @tablename + '"/> from a <see cref="DataRowBuilder"/>.
/// </summary>
/// <param name="builder">A <see cref="DataRowBuilder"/> object. </param>
public ' + @tablename + '(DataRowBuilder builder):base(builder){}
#endregion Constructors
#region Properties'
END
SELECT
'
/// <summary>
///
/// </summary>
/// <value></value>
public ' +
CASE c.name
WHEN 'bigint' THEN 'int'
WHEN 'binary' THEN 'bool'
WHEN 'bit' THEN 'bool'
WHEN 'char' THEN 'string'
WHEN 'datetime' THEN 'DateTime'
WHEN 'decimal' THEN 'decimal'
WHEN 'float' THEN 'decimal'
WHEN 'image' THEN 'byte[]'
WHEN 'int' THEN 'int'
WHEN 'money' THEN 'decimal'
WHEN 'nchar' THEN 'string'
WHEN 'ntext' THEN 'string'
WHEN 'numeric' THEN 'decimal'
WHEN 'nvarchar' THEN 'string'
WHEN 'real' THEN 'decimal'
WHEN 'smalldatetime' THEN 'DateTime'
WHEN 'smallint' THEN 'int'
WHEN 'smallmoney' THEN 'decimal'
WHEN 'text' THEN 'string'
WHEN 'timestamp' THEN 'DateTime'
WHEN 'tinyint' THEN 'int'
WHEN 'uniqueidentifier' THEN 'Guid'
WHEN 'varbinary' THEN 'byte[]'
WHEN 'varchar' THEN 'string'
ELSE c.name
END
+ ' ' + b.name + '
{
get
{
return Get' +
CASE c.name
WHEN 'bigint' THEN 'Int'
WHEN 'binary' THEN 'Bool'
WHEN 'bit' THEN 'Bool'
WHEN 'char' THEN 'String'
WHEN 'datetime' THEN 'DateTime'
WHEN 'decimal' THEN 'Decimal'
WHEN 'float' THEN 'Decimal'
WHEN 'image' THEN 'byte[]'
WHEN 'int' THEN 'Int'
WHEN 'money' THEN 'Decimal'
WHEN 'nchar' THEN 'String'
WHEN 'ntext' THEN 'String'
WHEN 'numeric' THEN 'Decimal'
WHEN 'nvarchar' THEN 'String'
WHEN 'real' THEN 'Decimal'
WHEN 'smalldatetime' THEN 'DateTime'
WHEN 'smallint' THEN 'Int'
WHEN 'smallmoney' THEN 'Decimal'
WHEN 'text' THEN 'String'
WHEN 'timestamp' THEN 'DateTime'
WHEN 'tinyint' THEN 'Int'
WHEN 'uniqueidentifier' THEN 'Guid'
WHEN 'varbinary' THEN 'byte[]'
WHEN 'varchar' THEN 'String'
ELSE c.name
END
+ '("' + b.name + '");
}
set
{
this["' + b.name + '"] = value;
}
}
'
FROM sysobjects a, syscolumns b, systypes c
WHERE a.xtype = 'U'
AND a.name = @tablename
AND a.id = b.id
AND b.xtype = c.xtype
AND b.xusertype = c.xusertype
AND b.name NOT IN ('UpdatedByUserKey', 'CreatedByUserKey')
ORDER BY b.name
SELECT
'
public User ' + LEFT(b.name,13) + '
{
get
{
return UserController.User(' + b.name + ', this.BusinessContainer);
}
}
'
FROM sysobjects a, syscolumns b
WHERE a.xtype = 'U'
AND a.name = @tablename
AND a.id = b.id
AND b.name IN ('UpdatedByUserKey', 'CreatedByUserKey')
ORDER BY b.name
IF @namespace IS NOT NULL
BEGIN
DECLARE @KeyCol varchar(256), @KeyType varchar(256), @pname varchar(256), @params varchar(1000), @assign varchar(1000)
DECLARE GetKeys CURSOR FOR
SELECT d.name,
CASE f.name
WHEN 'bigint' THEN 'int'
WHEN 'binary' THEN 'bool'
WHEN 'bit' THEN 'bool'
WHEN 'char' THEN 'string'
WHEN 'datetime' THEN 'DateTime'
WHEN 'decimal' THEN 'decimal'
WHEN 'float' THEN 'decimal'
WHEN 'image' THEN 'byte[]'
WHEN 'int' THEN 'int'
WHEN 'money' THEN 'decimal'
WHEN 'nchar' THEN 'string'
WHEN 'ntext' THEN 'string'
WHEN 'numeric' THEN 'decimal'
WHEN 'nvarchar' THEN 'string'
WHEN 'real' THEN 'decimal'
WHEN 'smalldatetime' THEN 'DateTime'
WHEN 'smallint' THEN 'int'
WHEN 'smallmoney' THEN 'decimal'
WHEN 'text' THEN 'string'
WHEN 'timestamp' THEN 'DateTime'
WHEN 'tinyint' THEN 'int'
WHEN 'uniqueidentifier' THEN 'Guid'
WHEN 'varbinary' THEN 'byte[]'
WHEN 'varchar' THEN 'string'
ELSE f.name
END
FROM sysobjects a, sysindexes b, sysobjects c, syscolumns d, sysindexkeys e, systypes f
WHERE a.id = b.id
AND a.id = c.parent_obj
AND c.name = b.name
AND b.indid = e.indid
AND d.colid = e.colid
AND a.id = d.id
AND a.id = e.id
AND a.name = @tablename
AND c.xtype='PK'
AND d.xtype = f.xtype
AND d.xusertype = f.xusertype
OPEN GetKeys
FETCH NEXT FROM GetKeys INTO @KeyCol, @KeyType
SET @params = ''
SET @assign = ''
WHILE @@FETCH_STATUS = 0
BEGIN
set @pname = LOWER(SUBSTRING(@KeyCol,1,1)) + SUBSTRING(@KeyCol,2,LEN(@KeyCol))
SET @params = @params + @KeyType + ' ' + @pname + ', '
SET @assign = @assign + ' this["' + @KeyCol + '"] = ' + @pname + ';
'
FETCH NEXT FROM GetKeys INTO @KeyCol, @KeyType
END
CLOSE GetKeys
DEALLOCATE GetKeys
SELECT
'
#endregion Properties
#region Methods
protected internal void InitializeNew(' + SUBSTRING(@params,1,LEN(@params) - 1) + ')
{
base.InitializeNew();
' + @assign + ' }
#endregion Methods
#region StaticProperties
#endregion StaticProperties
#region Static Members
#endregion Static Members
}
}
'
END
SET NOCOUNT ON
END
GO